﻿// 测试持久化状态功能
import { StorageManager, ScreenshotStorage, TimerStorage, EditorStorage } from './utils/storage'

async function testPersistentState() {
  console.log(' 开始测试持久化状态功能...')

  try {
    // 测试基础存储功能
    console.log(' 测试基础存储功能...')
    await StorageManager.set('test-key', { message: 'Hello World', timestamp: Date.now() })
    const testData = await StorageManager.get('test-key')
    console.log(' 基础存储测试通过:', testData)

    // 测试截屏存储
    console.log(' 测试截屏存储功能...')
    const mockScreenshot = {
      id: 'test-screenshot-1',
      dataUrl: '-data',
      timestamp: Date.now(),
      name: '测试截屏'
    }
    await ScreenshotStorage.saveScreenshot(mockScreenshot)
    const screenshots = await ScreenshotStorage.getScreenshots()
    console.log(' 截屏存储测试通过，保存了', screenshots.length, '张截屏')

    // 测试定时器存储
    console.log(' 测试定时器存储功能...')
    const mockTimers = [
      {
        id: 'test-timer-1',
        name: '测试定时器',
        duration: 300,
        remaining: 300,
        isRunning: false,
        isCompleted: false,
        createdAt: new Date().toISOString()
      }
    ]
    await TimerStorage.saveTimers(mockTimers)
    const timers = await TimerStorage.getTimers()
    console.log(' 定时器存储测试通过，保存了', timers.length, '个定时器')

    // 测试编辑器存储
    console.log(' 测试编辑器存储功能...')
    const mockContent = '<h1>测试内容</h1><p>这是一个测试文档</p>'
    await EditorStorage.saveContent(mockContent)
    const content = await EditorStorage.getContent()
    console.log(' 编辑器存储测试通过，内容长度:', content.length)

    // 测试数据清理
    console.log(' 测试数据清理功能...')
    await StorageManager.remove('test-key')
    await ScreenshotStorage.clearScreenshots()
    await TimerStorage.saveTimers([])
    await EditorStorage.saveContent('')
    console.log(' 数据清理测试通过')

    console.log(' 所有持久化状态功能测试通过！')

  } catch (error) {
    console.error(' 测试失败:', error)
  }
}

// 如果是在浏览器环境中运行
if (typeof window !== 'undefined') {
  testPersistentState()
}

export { testPersistentState }
